//
//  SubDayColCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/9/6.
//

import UIKit

class SubDayColCell: UICollectionViewCell {
    
    lazy var subImage: UIImageView = {
        return UIImageView()
    }()
    
    lazy var dayLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 9)
        label.textColor = .white
        label.textAlignment = .center
        return label
    }()
    
    lazy var subBtn: UIButton = {
        let btn = UIButton(type: .custom)
        return btn
    }()
    
    var model: TicketModel? {
        didSet {
            if let m = model {
                switch m.status {
                case 1:
                    subImage.image = UIImage(named: "ticket_bg_1")
                    subBtn.setImage(UIImage(named: "book_ticket_white"), for: .normal)
                case 2:
                    subImage.image = UIImage(named: "ticket_bg_2")
                    subBtn.setImage(UIImage(named: "library_book_sel"), for: .normal)
                case 3:
                    subImage.image = UIImage(named: "ticket_bg_3")
                    subBtn.setImage(UIImage(named: "ticket_sel"), for: .normal)
                default: break
                }
                dayLabel.text = "第\(m.day ?? 0)天"
                let color = UIColor.init(named: m.status == 2 ? "red_FE95B4" : ( m.status == 1 ? "gray_D0D0D0" : "purple_AB95FE"))
                backgroundColor = color
                subImage.image?.withTintColor(color!)
                wn_cornerWithBorder(4, 1, color!)
                layer.masksToBounds = true
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(subImage)
        addSubview(dayLabel)
        addSubview(subBtn)
        subImage.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        dayLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-2)
        }
        subBtn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(10)
            make.width.height.equalTo(20)
        }
        wn_cornerWithBorder(4)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
